<template>
	<view class="content">
		<nav-bar leftType="1" leftText="" bgColor="#fff"></nav-bar>
		
		<view class="user-info">
			<view class="left">
				<image class="img" :src="userImg[imgIndex]" mode="aspectFit"></image>
			</view>
			<view class="info">
				<view class="name">{{loginInfo.nickname}}</view>
				<view class="number">学员编号：{{loginInfo.id}}</view>
			</view>
			<view class="right"><view class="iconfont icon-fanhui base-fanhui"></view></view>
		</view>
		<view class="btn-item">
			<simpleItem leftIcon="icon-fuzhi" title="刷题记录" rightIcon="icon-fanhui base-fanhui" mg8 rightText="AI分析记录" @click.native="practiceRecord('1')"></simpleItem>
			<simpleItem leftIcon="icon-lishihangcheng" title="错题/收藏" rightIcon="icon-fanhui base-fanhui" @click.native="practiceRecord('2')"></simpleItem>
			<simpleItem leftIcon="icon-yijianfankui" title="我的笔记" rightIcon="icon-fanhui base-fanhui" @click.native="practiceRecord('3')"></simpleItem>
			<simpleItem leftIcon="icon-pinglun" title="我的评论" rightIcon="icon-fanhui base-fanhui" @click.native="practiceRecord('4')"></simpleItem>
			<simpleItem leftIcon="icon-kuandai" title="电脑端人机对话" rightIcon="icon-fanhui base-fanhui" @click.native="practiceRecord('5')"></simpleItem>
			<simpleItem leftIcon="icon-kefu" title="在线答疑老师" rightIcon="icon-fanhui base-fanhui" mg8 @click.native="practiceRecord('6')"></simpleItem>
			<simpleItem leftIcon="icon-qiehuan" title="切换题库" rightIcon="icon-fanhui base-fanhui" :rightText="$store.getters.getKeMuName" @click.native="practiceRecord('7')"></simpleItem>
		</view>
		<view class="beian" @click="openIcpLink">ICP备案号：蜀ICP备2022016990号-9A</view>
		<servicePopup type="5" ref="popup"></servicePopup>
	</view>
</template>

<script>
	import { debounce } from 'lodash';
	import simpleItem from "@/components/simple-item.vue"
	import servicePopup from "@/components/servicePopup.vue"
	export default {
		components: {
			simpleItem,
			servicePopup
		},
		data() {
			return {
				userImg: [
					'https://1322345190.vod-qcloud.com/fd615140vodcq1322345190/b076299a5145403700528334195/DMaaHfUfDecA.jpg',
					'https://1322345190.vod-qcloud.com/fd615140vodcq1322345190/c9f2721a5145403700525391582/5n6w5lkucrEA.jpg',
					'https://1322345190.vod-qcloud.com/fd615140vodcq1322345190/d35fb6fb5145403700532512878/FgsgH7MKR1UA.jpg',
					'https://1322345190.vod-qcloud.com/fd615140vodcq1322345190/81598f705145403700524550360/3r21nxeHIjkA.jpg',
					'https://1322345190.vod-qcloud.com/fd615140vodcq1322345190/b07745fc5145403700528336249/Of9an4but50A.jpg',
					'https://1322345190.vod-qcloud.com/fd615140vodcq1322345190/1db5dedc5145403700526661556/IW4kPWncmZkA.jpg',
					'https://1322345190.vod-qcloud.com/fd615140vodcq1322345190/1ac9f8df5145403700519771357/OAQ1PcaJXboA.png',
				],
				imgIndex: 0,
			}
		},
		computed: {
			loginInfo() {
				return this.$store.state.loginInfo;
			},
		},
		onLoad() {
		},
		onShow() {
			if(this.$common.isEmpty(this.loginInfo)){
				uni.showToast({
					title: '请先绑定手机号',
					icon: 'none'
				})
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
			this.imgIndex = Math.floor(Math.random() * 7);
		},
		methods: {
			openIcpLink() {
			      const icpUrl = 'https://beian.miit.gov.cn/'; // 替换为你的备案链接
			      
			      // #ifdef H5
			      window.open(icpUrl, '_blank');
			      // #endif
			      
			      // #ifdef APP-PLUS
			      plus.runtime.openURL(icpUrl, (error) => {
			        if (error) {
			          console.error('打开链接失败:', error);
			          uni.showToast({
			            title: '打开链接失败',
			            icon: 'none'
			          });
			        }
			      });
			      // #endif
			      
			      // #ifdef MP-WEIXIN
			      // 小程序中需要使用web-view组件或在app.json中配置业务域名
			      // 这里提供两种方案：
			      
			      // 方案1：跳转到web-view页面
				  uni.navigateTo({
				  	url: '/pagesD/webView/index?url='+encodeURIComponent(icpUrl)
				  })
			      // #endif
			},
			cutClick(){
				uni.navigateTo({
					url: `/pages/cutDrawer/index`
				})
			},
			practiceRecord: debounce(function(type){
				if(type=='1'){
					uni.navigateTo({
						url: `/pagesC/topicRelated/practiceRecord`
					})
				}else if(type=='2'){
					uni.navigateTo({
						url: `/pagesC/topicRelated/mistakes`
					})
				}else if(type=='3'){
					uni.navigateTo({
						url: `/pagesC/topicRelated/notes?type=2`
					})
				}else if(type=='4'){
					uni.navigateTo({
						url: `/pagesC/topicRelated/notes?type=1`
					})
				}else if(type=='5'){
					// #ifdef MP-WEIXIN
					uni.navigateToMiniProgram({
						appId: 'wx550e7f9a5a7910d3'
					})
					// #endif
				}else if(type=='6'){
					this.$refs.popup.serviceModelShow()
				}else if(type=='7'){
					this.cutClick()
				}
			},500),
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .perch{
		background-color: #fff;
	}
	.content{
		min-height: 100vh;
		background-color: #F8F8F8;
	}
	.user-info{
		display: flex;
		align-items: center;
		padding: 10rpx 56rpx 44rpx 36rpx;
		background-color: #fff;
		.left,.right{
			flex-shrink: 0;
		}
		.left{
			width: 130rpx;
			height: 130rpx;
			margin-right: 30rpx;
			.img{
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}
		.info{
			flex: 1;
			.name{
				margin-bottom: 28rpx;
				font-weight: 600;
				font-size: 36rpx;
				color: #222;
			}
			.number{
				font-size: 28rpx;
				color: #6E6E6E;
			}
		}
		.right{
			color: #B6B6B6;
			.iconfont{
				font-size: 24rpx;
				font-weight: bold;
			}
		}
	}
	.btn-item{
		padding: 10rpx;
	}
	.beian{
		position: fixed;
		left: 0;
		right: 0;
		bottom: 30rpx;
		text-align: center;
		color: #DADADA;
		font-size: 24rpx;
	}
</style>
